# -*- coding: utf-8 -*-
import pika
import sys

# 创建连接对象，配置账号密码和地址
parameters = pika.URLParameters('amqp://root:123qwe@118.89.175.35:5672/%2F')
connection = pika.BlockingConnection(parameters)
# 获取连接通道
channel = connection.channel()
# durable=True 开启持久化
channel.queue_declare(queue='task_queue', durable=True)

message = ' '.join(sys.argv[1:]) or "Hello  World!."
print(message)
channel.basic_publish(
    exchange='',
    routing_key='task_queue',
    body=message,
    properties=pika.BasicProperties(
        delivery_mode=2,  # make message persistent
    ))
print(" [x] Sent %r" % message)
connection.close()
